<?php $i = 0;?>
<table  class="datagrid">
    <tr>
        <th width="50">#</th>
        <th width="130">name</th>
        <th width="20">level</th>
        <th width="150">alliance</th>
        <th width="20">onl</th>
        <th width="20">pro</th>
        <th width="50" style="text-align: right"><a href="javascript:void(0)" title="sort by Crystal" onclick="viewData(this, 'res1')">C</a></th>
        <th width="50" style="text-align: right"><a href="javascript:void(0)" title="sort by Gas" onclick="viewData(this, 'res2')">G</a></th>
        <th width="50" style="text-align: right"><a href="javascript:void(0)" title="sort by Energy" onclick="viewData(this, 'res3')">E</a></th>
        <th width="50" style="text-align: right"><a href="javascript:void(0)" title="sort by Uranium" onclick="viewData(this, 'res4')">U</a></th>
        <th width="100" style="text-align: right"><a href="javascript:void(0)" title="sort by Buildin's HP" onclick="viewData(this, 'hp')">HP</a></th> 
        <th width="20" style="text-align: right" title="Attack boost">Atk</th>
        <th width="20" style="text-align: right" title="HP boost">Def</th>
        <th width="20" style="text-align: right" title="Level of Command Center">CC</th>
        <th width="100" style="text-align: center">updated time</th>
        <th width="250">find</th>
        <th width="100"></th>
    </tr>
    <?php foreach ($data as $item): ?>
        <tr id="p-<?php echo $item['id'] ?>">
            <td class="p-name"><?php $i++;echo "#$i" ?></td>
            <td class="p-name"><?php echo $item['name'] ?></td>
            <td class="p-level"><?php echo $item['level'] ?></td>
            <td class="p-alliance_name"><?php echo $item['alliance_name'] ?></td>
            <td class="p-online"><?php echo $item['online'] ?></td>
            <td class="p-damage_protection"><?php echo $item['damage_protection'] ?></td>
            <td class="p-res1" style="text-align: right"><?php echo$item['res1']?></td>
            <td class="p-res2" style="text-align: right"><?php echo$item['res2']?></td>
            <td class="p-res3" style="text-align: right"><?php echo$item['res3']?></td>
            <td class="p-res4" style="text-align: right"><?php echo$item['res4']?></td>
            <td class="p-res4" style="text-align: right"><?php echo number_format($item['building_hp'],0)?></td>
            <td class="p-atk" style="text-align: right"><?php echo ($item['attack_boost'])?'A':''?></td>
            <td class="p-def" style="text-align: right"><?php echo ($item['hp_boost'])?'D':''?></td>
            <td class="p-last_update" style="text-align: center"><?php echo $item['cc_level'] ?></td>
            <td class="p-last_update" style="text-align: center"><?php echo $item['last_update'] ?></td>
            <td class="p-source"><?php echo $item['source'] ?></td>
            <td class="action">
                <a class="button" href="javascript:void(0)" onclick="reloadPlayer(<?php echo $item['id'] ?>)">Reload</a>
            </td>
        </tr>
    <?php endforeach; ?>
</table>

<script type="text/javascript">

function reloadPlayer(id) {
    var p = $('tr#p-'+id);
    //$('td', p).css('display', 'hidden');
    extraData = '';
    
    $.ajax({
        url:'index/updatePlayer',
        data:'id='+id+'&'+extraData,
        dataType:'json',
        success:function(data){           
           $('.p-name', p).html(data.name);
           $('.p-level', p).html(data.level);
           $('.p-alliance_name', p).html(data.alliance_name);
           $('.p-online', p).html(data.online);
           $('.p-damage_protection', p).html(data.damage_protection);
           $('.p-res1', p).html(data.res1);
           $('.p-res2', p).html(data.res2);
           $('.p-res3', p).html(data.res3);
           $('.p-res4', p).html(data.res4);
           $('.p-last_update', p).html(data.last_update);
            //$('#console').append('<br />');
            //$('#console').append(html +'<br />');
            
        }
    });

}


</script>